﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TutorCenter.DataAccess.DataContext
{
    public class UnitOfWork : IUnitOfWork
    {
        private DbContext dbContext;

        public DbContext GetDbContext()
        {
            return dbContext;
        }
        public UnitOfWork(DbContext dbContext)
        {
            this.dbContext = dbContext;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        public DbContext DbContext()
        {
            return dbContext;
        }

        public void Commit()
        {
            this.dbContext.SaveChanges();
        }

        public void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (dbContext != null)
                {
                    this.dbContext.Dispose();
                    this.dbContext = null;
                }
            }
        }
    }
}
